package com.xiaomage.view.draw8

import android.content.Context
import android.graphics.*
import android.view.View
import android.R.attr.bitmap
import android.opengl.ETC1.getWidth
import android.opengl.ETC1.getHeight
import android.graphics.ColorMatrixColorFilter
import android.graphics.ColorMatrix



/**
 * Created by Administrator on 2018/1/6.
 */
class MyView(context: Context):View(context) {
    private lateinit var paint:Paint
    private lateinit var paint2:Paint
    private lateinit var paint3:Paint
    private lateinit var paint4:Paint
    private lateinit var paint5:Paint
    private lateinit var paint6:Paint
    private lateinit var paint7:Paint
    private lateinit var paint8:Paint
    private lateinit var paint9:Paint
    private lateinit var paint10:Paint
    private lateinit var paint11:Paint
    private lateinit var bitmap:Bitmap
    init {
        paint=getPaint()
        paint2=getPaint()
        paint3=getPaint()
        paint4=getPaint()
        paint5=getPaint()
        paint6=getPaint()
        paint7=getPaint()
        paint8=getPaint()
        paint9=getPaint()
        paint10=getPaint()
        paint11=getPaint()
        bitmap=BitmapFactory.decodeResource(this.resources,R.drawable.dog)
    }

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        //绘制原始路径
        canvas.drawBitmap(bitmap,null,
                Rect(0,0,500,500*bitmap.height/bitmap.width),
                paint)

        canvas.translate(0f,((500*bitmap.height)/bitmap.width).toFloat()+50)
        //定义ColorMatrix
        val colorMatrix=ColorMatrix(floatArrayOf(
                0f,0f,0f,0f,0f,
                0f,0f,0f,0f,0f,
                0f,0f,1f,0f,0f,
                0f,0f,0f,1f,0f
        ))
        paint2.colorFilter=ColorMatrixColorFilter(colorMatrix)
        canvas.drawBitmap(bitmap,null,
                Rect(0,0,500,500*bitmap.height/bitmap.width),
                paint2)


        canvas.translate(0f,((500*bitmap.height)/bitmap.width).toFloat()+50)
        //定义ColorMatrix
        val colorMatrix2=ColorMatrix(floatArrayOf(
                1f,0f,0f,0f,0f,
                0f,1f,0f,0f,50f,
                0f,0f,1f,0f,0f,
                0f,0f,0f,1f,0f
        ))
        paint3.colorFilter=ColorMatrixColorFilter(colorMatrix2)
        canvas.drawBitmap(bitmap,null,
                Rect(0,0,500,500*bitmap.height/bitmap.width),
                paint3)

        canvas.translate(0f,((500*bitmap.height)/bitmap.width).toFloat()+50)
        //定义ColorMatrix
        val colorMatrix4=ColorMatrix(floatArrayOf(
                -1f,0f,0f,0f,255f,
                0f,-1f,0f,0f,255f,
                0f,0f,-1f,0f,255f,
                0f,0f,0f,1f,0f
        ))
        paint4.colorFilter=ColorMatrixColorFilter(colorMatrix4)
        canvas.drawBitmap(bitmap,null,
                Rect(0,0,500,500*bitmap.height/bitmap.width),
                paint4)

        canvas.translate(0f,((500*bitmap.height)/bitmap.width).toFloat()+50)
        //定义ColorMatrix
        val colorMatrix5=ColorMatrix(floatArrayOf(
                1.2f,0f,0f,0f,0f,
                0f,1.2f,0f,0f,50f,
                0f,0f,1.2f,0f,0f,
                0f,0f,0f,1.2f,0f
        ))
        paint5.colorFilter=ColorMatrixColorFilter(colorMatrix5)
        canvas.drawBitmap(bitmap,null,
                Rect(0,0,500,500*bitmap.height/bitmap.width),
                paint5)


        canvas.translate(0f,((500*bitmap.height)/bitmap.width).toFloat()+50)
        //定义ColorMatrix
        val colorMatrix6=ColorMatrix(floatArrayOf(
                0f,1f,0f,0f,0f,
                1f,1f,0f,0f,0f,
                0f,0f,1f,0f,0f,
                0f,0f,0f,1f,0f
        ))
        paint6.colorFilter=ColorMatrixColorFilter(colorMatrix6)
        canvas.drawBitmap(bitmap,null,
                Rect(0,0,500,500*bitmap.height/bitmap.width),
                paint6)


        canvas.translate(0f,((500*bitmap.height)/bitmap.width).toFloat()+50)
        //定义ColorMatrix
        val colorMatrix7=ColorMatrix(floatArrayOf(
                0.213f,0.715f,0.072f,0f,0f,
                0.213f,0.715f,0.072f,0f,0f,
                0.213f,0.715f,0.072f,0f,0f,
                0f,0f,0f,1f,0f
        ))
        paint7.colorFilter=ColorMatrixColorFilter(colorMatrix7)
        canvas.drawBitmap(bitmap,null,
                Rect(0,0,500,500*bitmap.height/bitmap.width),
                paint7)

        canvas.translate(0f,((500*bitmap.height)/bitmap.width).toFloat()+50)
        //定义ColorMatrix
        val colorMatrix8=ColorMatrix(floatArrayOf(
                0.5f,0.5f,0.5f,0f,0f,
                0.33f,0.33f,0.33f,0f,0f,
                0.25f,0.25f,0.25f,0f,0f,
                0f,0f,0f,1f,0f
        ))
        paint8.colorFilter=ColorMatrixColorFilter(colorMatrix8)
        canvas.drawBitmap(bitmap,null,
                Rect(0,0,500,500*bitmap.height/bitmap.width),
                paint8)

        //设置饱和度

    }

    //设置饱和度
    private fun setSaturation(canvas:Canvas){
        canvas.translate(0f,((500*bitmap.height)/bitmap.width).toFloat()+50)
        //定义ColorMatrix
        val colorMatrix9=ColorMatrix(floatArrayOf(
                0.5f,0.5f,0.5f,0f,0f,
                0.33f,0.33f,0.33f,0f,0f,
                0.25f,0.25f,0.25f,0f,0f,
                0f,0f,0f,1f,0f
        ))
        paint9.colorFilter=ColorMatrixColorFilter(colorMatrix9)
        canvas.drawBitmap(bitmap,null,
                Rect(0,0,500,500*bitmap.height/bitmap.width),
                paint9)
    }

    private fun getPaint():Paint{
        val paint=Paint()
        paint.isAntiAlias=true
        paint.style=Paint.Style.STROKE
        paint.strokeWidth=5f
        paint.color= Color.parseColor("#fc4c4f")
        return paint
    }

}